package lsl.leetCode.year2023.test0125;

import java.util.Arrays;

public class test88 {
    public static void main(String[] args) {
        int[] nums1 = {1, 7, 8, 0,0,0,0,0,0,0};
        int[] nums2 = {2, 2, 3, 23, 17, 28, 41};
        merge(nums1, 3, nums2, 7);
        System.out.println(Arrays.toString(nums1));
    }

    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int[] sorted = new int[m + n];
        int p1 = 0;
        int p2 = 0;
        int cur;
        while (p1 < m || p2 < n) {
            if (p1 == m) {
                cur = nums2[p2++];
            } else if (p2 == n) {
                cur = nums1[p1++];
            } else if (nums1[p1] < nums2[p2]) {
                cur = nums1[p1++];
            } else {
                cur = nums2[p2++];
            }
            sorted[p1 + p2 - 1] = cur;
        }
        for (int i = 0; i != m + n; ++i) {
            nums1[i] = sorted[i];
        }
    }
}
